import { http } from '@/utils/request';
export default {
  /**
   * 业务接口
   */
  // wxMenu列表
  getWxMenuList: (data) => http.get('/wxMenu/list', data),
  // banner列表
  getWxBannerList: (data) => http.get('/wxBanner/list', data),
  // 房屋列表
  getOfficeBuildingPage: (data) => http.get('/officeBuilding', data),
  getOfficeBuildingTemplateList: (data) => http.get('/officeBuildingTemplate/list', data),
  // 写字楼详情
  getOfficeBuildingDetail: (id) => http.get('/officeBuilding/' + id),
  getOfficeBuildingTemplateDetail: (id) => http.get('/officeBuildingTemplate/' + id),

  /**
   * 办公用品商城
   */
  // 商品分类
  getOfficeCategoryTree: (data) => http.get('/category/tree', data),
  getOfficeCategoryList: () => http.get('/category/list'),

  // 商品管理
  getOfficeProductList: (data) => http.get('/product', data),
  getOfficeProduct: (id) => http.get('/product/' + id),
  /**
   * 桶装水商城
   */
  // 商品分类
  getWaterCategoryTree: (data) => http.get('/category/tree', data),

  // 商品管理
  getWaterProductList: (data) => http.get('/product', data),
  getWaterProductDetail: (data) => http.get('/product/' + data.id),
  /**
   * 购物车
   */
  /**
   * // 添加购物车
   * const cartItemCreate = '/tiny-shop/v1/member/cart-item/create';
   * // 购物车列表
   * const cartItemList = '/tiny-shop/v1/member/cart-item/index';
   * // 购物车列表
   * const cartItemCount = '/tiny-shop/v1/member/cart-item/count';
   * // 删除购物车商品
   * const cartItemDel = '/tiny-shop/v1/member/cart-item/delete-ids';
   * // 清空购物车
   * const cartItemClear = '/tiny-shop/v1/member/cart-item/clear';
   * // 修改购物车商品数量
   * const cartItemUpdateNum = '/tiny-shop/v1/member/cart-item/update-num';
   * // 修改购物车商品sku
   * const cartItemUpdateSku = '/tiny-shop/v1/member/cart-item/update-sku';
   */
  // 添加购物车
  addCartItem: (data) => http.post('/cart', data),
  // 购物车列表
  getCartItemList: (data) => http.get('/cart/list', data),
  // 获取结算购物车
  getSettleCartItemList: (data) => http.post('/cart/settle', data),
  // 购物车列表
  getCartItemCount: (data) => http.get('/cart/count', data),
  // 删除购物车商品
  deleteCartItem: (id) => http.delete('/cart/' + id),
  deleteAllCartItem: (data) => http.post('/cart/deleteAll', data),
  // 清空购物车
  clearCartItem: (data) => http.post('/cart/clear', data),
  // 修改购物车商品数量
  updateCartItemNum: (data) => http.post('/cart/update-num', data),
  // 全选
  updateAllCartItemSelected: (data) => http.post('/cart/update-all-selected', data),
  // 选中
  updateCartItemSelected: (data) => http.post('/cart/update-selected', data),
  /**
   * 地址管理
   */
  // 获取用户地址列表
  getUserAddressList: (data) => http.get('/address/user', data),
  // 获取默认地址
  getDefaultAddress: (data) => http.get('/address/getDefault', data),
  // 添加地址
  addAddress: (data) => http.post('/address', data),
  // 更新地址
  updateAddress: (id, data) => http.put(`/address/${id}`, data),
  // 设置默认地址
  setDefaultAddress: (data) => http.post('/address/setDefault', data),
  // 删除地址
  deleteAddress: (id) => http.delete(`/address/${id}`),

  /**
   * 用户管理
   */
  // 用户登录
  login: (data) => http.post('/member/login', data),
  // 微信登录
  wechatLogin: (data) => http.post('/member/wechatLogin', data),
  // 用户注册
  register: (data) => http.post('/member/register', data),
  // 获取用户信息
  getUserInfo: () => http.get('/member/info'),
  // 更新用户信息
  updateUserInfo: (data) => http.put('/member/updateInfo', data),
  // 上传文件
  uploadFile: (filePath, name = 'file') => {
    return new Promise((resolve, reject) => {
      uni.uploadFile({
        url: uni.$u.http.config.baseUrl + '/upload/file',
        filePath: filePath,
        name: name,
        header: {
          Authorization: 'Bearer ' + uni.getStorageSync('token')
        },
        success: (res) => {
          try {
            const data = JSON.parse(res.data);
            if (data.code === 200) {
              resolve(data.data);
            } else {
              reject(data);
            }
          } catch(e) {
            reject(e);
          }
        },
        fail: (err) => {
          reject(err);
        }
      });
    });
  },
  /**
   * 订单管理
   */
  // 创建订单
  createOrder: (data) => http.post('/order', data),
  getOrderDetail: (id) => http.get('/order/' + id),

}
